package com.sinosun.autotestmachine.tools.proxy;

import com.sinosun.autotestmachine.App;
import com.sinosun.mstplib.DeviceType;
import com.sinosun.mstplib.MstpClient;
import com.sinosun.mstplib.util.SDKContext;

public class ProxyWrapper {
	private DeviceType deviceType = DeviceType.DEVICE_TYPE_1;
	private int uploadLimit = 51 * 1014 * 1024;
	private MstpClient mstpClient = null;
	
	public void setMstpClient(MstpClient mstpClient) {
		this.mstpClient = mstpClient;
	}

	public ProxyWrapper(DeviceType deviceType, int uploadLimit) {
		if (deviceType != null ) {
			this.deviceType = deviceType;
		}
		if (uploadLimit != -1) {
			this.uploadLimit = uploadLimit;
		}
		initTestPlatform();
	}
	
	public ProxyWrapper(DeviceType deviceType) {
		this(deviceType, -1);
	}
	
	public ProxyWrapper() {
		this(null, -1);
	}
	
	public ProxyWrapper(int uploadLimit) {
		this(null, uploadLimit);
	}

	/*
	 * configFile 配置文件名称 return 0表示成功，失败返回错误码
	 */
	private int initTestPlatform() {
		SDKContext.setUploadFileMaxBytes(uploadLimit);
	    SDKContext.setDeviceType(deviceType);
		int ret = MstpClient.initSdk(App.getInstance().getApplicationContext(), App.getInstance().getAppFilePath());
		return ret;
	}

	/**
	 * 同步登陆账号
	 * @param paramJson
	 * @return
	 */
	public int sycnLogin(String paramJson) {
		return LoginModule.sycnLogin(this, mstpClient, paramJson);
	}
	
	/**
	 * 同步的登出账号
	 * @return
	 */
	public int sycnLogout() {
		return LoginModule.sycnLogout(mstpClient);
	}
	
	/**
	 * 同步的发送多条数据
	 * @param paramJson
	 * @return
	 */
	public int syncSendMessage(String paramJson, String cacheParam) {
		return MessageModule.syncSendMessage(mstpClient, paramJson, cacheParam);
	}
	
	/**
	 * 同步的发送多条数据
	 * @param paramJson
	 * @return
	 */
	public int syncSendMessage(String paramJson) {
		return MessageModule.syncSendMessage(mstpClient, paramJson, null);
	}
	
	/**
	 * 同步校验消息接受情况
	 * @param paramJson
	 * @return
	 */
	public int verifyRecvMessage(String paramJson) {
		return MessageModule.verifyRecvMessage(mstpClient, paramJson);
	}
	
	/**
	 * 同步的发送已读信令
	 * @param paramJson
	 * @return
	 */
	public int sendHaveReadMessage(String paramJson) {
		return MessageModule.sendHaveReadMessage(mstpClient, paramJson);
	}
	
	/**
	 * 验证是否收到已读（与缓存的数据进行比较）
	 * @param paramJson
	 * @return
	 */
	public int verifyHaveReadMessage(String paramJson) {
		return MessageModule.verifyHaveReadMessage(mstpClient, paramJson);
	}
	
	/**
	 * 同步的发送撤销信令
	 * @param paramJson
	 * @return
	 */
	public int sendRevokeMessage(String paramJson) {
		return MessageModule.sendRevokeMessage(mstpClient, paramJson);
	}
	
	/**
	 * 验证撤销消息
	 * @param paramJson
	 * @return
	 */
	public int verifyRevokeMessage(String paramJson) {
		return MessageModule.verifyRevokeMessage(mstpClient, paramJson);
	}
	
	/**
	 * 同步的创建群组
	 * @param paramJSON
	 * @param cacheParam
	 * @return
	 */
	public int createGroup(String paramJSON, String cacheParam) {
		return GroupModule.createGroup(mstpClient, paramJSON, cacheParam);
	}
	
	/**
	 * 同步的创建群组
	 * @param paramJSON
	 * @return
	 */
	public int createGroup(String paramJSON) {
		return GroupModule.createGroup(mstpClient, paramJSON, null);
	}
	
	/**
	 * 同步的解散群组
	 * @param paramJson
	 * @return
	 */
	public int dismissGroup(String paramJson) {
		return GroupModule.dismissGroup(mstpClient, paramJson);
	}
	
	/**
	 * 同步的加入群组
	 * @return
	 */
	public int joinGroup(String paramJson) {
		return GroupModule.joinGroup(mstpClient, paramJson);
	}
	
	/**
	 * 验证群组成员信息
	 * @param paramJson
	 * @return
	 */
	public int verifyUserInGroup(String paramJson) {
		return GroupModule.verifyUserInGroup(mstpClient, paramJson);
	}
	
	/**
	 * 离开群组
	 * @param paramJson
	 * @return
	 */
	public int leaveGroup(String paramJson) {
		return GroupModule.leaveGroup(mstpClient, paramJson);
	}
	
	/**
	 * 移除群组成员
	 * @param paramJson
	 * @return
	 */
	public int removeGroupMember(String paramJson) {
		return GroupModule.removeGroupMember(mstpClient, paramJson);
	}
	
	/**
	 * 查询群组信息，用于检测异常情况
	 * @param paramJson
	 * @return
	 */
	public int queryGroupInfo(String paramJson) {
		return GroupModule.queryGroupInfo(mstpClient, paramJson);
	}
	
	/**
	 * 邀请其他人进入群组
	 * @param paramJson
	 * @return
	 */
	public int inviteGroupMember(String paramJson) {
		return GroupModule.inviteGroupMember(mstpClient, paramJson);
	}
	
	/**
	 * 设置昵称
	 * @param paramJson
	 * @return
	 */
	public int setMemberNickname(String paramJson) {
		return GroupModule.setMemberNickname(mstpClient, paramJson);
	}
	
	/**
	 * 查询群组成员，测试异常情况
	 * @param paramJson
	 * @return
	 */
	public int queryGroupMember(String paramJson) {
		return GroupModule.queryGroupMember(mstpClient, paramJson);
	}
	
	/**
	 * 更新群组信息
	 * @param paramJson
	 * @return
	 */
	public int updateGroupInfo(String paramJson) {
		return GroupModule.updateGroupInfo(mstpClient, paramJson);
	}
	
	/**
	 * 同步的发送通知
	 * @param paramJson
	 * @param cacheJson
	 * @return
	 */
	public int syncSendP2PNotification(String paramJson, String cacheJson) {
		return NotificationModule.syncSendP2PNotification(mstpClient, paramJson, cacheJson);
	}
	
	/**
	 * 同步的发送通知
	 * @param paramJson
	 * @return
	 */
	public int syncSendP2PNotification(String paramJson) {
		return NotificationModule.syncSendP2PNotification(mstpClient, paramJson, null);
	}
	
	/**
	 * 接收通知验证
	 * @param paramJson
	 * @return
	 */
	public int verifyRecvNotify(String paramJson) {
		return NotificationModule.verifyRecvNotify(mstpClient, paramJson);
	}
	
	/**
	 * 同步的并发上传文件
	 * @param paramJson
	 * @param cacheJson
	 * @return
	 */
	public int syncUploadFile(String paramJson, String cacheJson) {
		return FileModule.syncUploadFile(mstpClient, paramJson, cacheJson);
	}
	
	/**
	 * 同步的并发上传文件
	 * @param paramJson
	 * @return
	 */
	public int syncUploadFile(String paramJson) {
		return FileModule.syncUploadFile(mstpClient, paramJson, null);
	}
	
	/**
	 * 同步并发的下载文件
	 * @param paramJson
	 * @return
	 */
	public int syncDownloadFile(String paramJson) {
		return FileModule.syncDownloadFile(mstpClient, paramJson);
	}
	
	/**
	 * 同步取消并发的上传动作
	 * @param paramJson
	 * @return
	 */
	public int cancelUploadFileAndVerify(String paramJson) {
		return FileModule.cancelUploadFileAndVerify(mstpClient, paramJson);
	}
	
	/**
	 * 同步取消并发的下载动作
	 * @param paramJson
	 * @return
	 */
	public int cancelDownloadFileAndVerify(String paramJson) {
		return FileModule.cancelDownloadFileAndVerify(mstpClient, paramJson);
	}
	
	/**
	 * 同步的秒传测试接口
	 * @param paramJson
	 * @return
	 */
	public int uploadDuplicateFileAndVerify(String paramJson) {
		return FileModule.uploadDuplicateFileAndVerify(mstpClient, paramJson);
	}
	
	/**
	 * 创建网盘账号
	 * @return
	 */
	public int createCloudDiskAccount() {
		return CloudDiskModule.createCloudDiskAccount(mstpClient);
	}
	
	/**
	 * 清理网盘环境
	 * @return
	 */
	public int tearDownCloudDiskEnv() {
		return CloudDiskModule.tearDownCloudDiskEnv(mstpClient);
	}
	
	/**
	 * 创建网盘文件夹
	 * @param paramJson
	 * @param cacheJson
	 * @return
	 */
	public int createCloudDiskFolder(String paramJson, String cacheJson) {
		return CloudDiskModule.createCloudDiskFolder(mstpClient, paramJson, cacheJson);
	}
	
	/**
	 * 创建网盘文件夹
	 * @param paramJson
	 * @return
	 */
	public int createCloudDiskFolder(String paramJson) {
		return CloudDiskModule.createCloudDiskFolder(mstpClient, paramJson, null);
	}
	
	/**
	 * 创建重名的文件夹
	 * @param paramJson
	 * @return
	 */
	public int createDuplicateCloudDiskFolder(String paramJson) {
		return CloudDiskModule.createDuplicateCloudDiskFolder(mstpClient, paramJson);
	}
	
	/**
	 * 上传文件到网盘
	 * @param paramJson
	 * @param cacheJson
	 * @return
	 */
	public int uploadFileToCloudDisk(String paramJson, String cacheJson) {
		return CloudDiskModule.uploadFileToCloudDisk(mstpClient, paramJson, cacheJson);
	}
	
	/**
	 * 上传文件到网盘
	 * @param paramJson
	 * @return
	 */
	public int uploadFileToCloudDisk(String paramJson) {
		return CloudDiskModule.uploadFileToCloudDisk(mstpClient, paramJson, null);
	}
	
	/**
	 * 从网盘下载文件
	 * @param paramJson
	 * @return
	 */
	public int downloadCloudDiskFile(String paramJson) {
		return CloudDiskModule.downloadCloudDiskFile(mstpClient, paramJson);
	}
	
	/**
	 * 取消上传文件至网盘
	 * @param paramJson
	 * @return
	 */
	public int cancelUploadFileToCloudDisk(String paramJson) {
		return CloudDiskModule.cancelUploadFileToCloudDisk(mstpClient, paramJson);
	}
	
	/**
	 * 取消下载网盘的文件
	 * @param paramJson
	 * @return
	 */
	public int cancelDownloadCloudDiskFile(String paramJson) {
		return CloudDiskModule.cancelDownloadCloudDiskFile(mstpClient, paramJson);
	}
	
	/**
	 * 分类浏览
	 * @param paramJson
	 * @return
	 */
	public int cloudDiskBrowseByCategory(String paramJson) {
		return CloudDiskModule.cloudDiskBrowseByCategory(mstpClient, paramJson);
	}
	
	/**
	 * 移动网盘节点
	 * @param paramJson
	 * @return
	 */
	public int moveCloudDiskNode(String paramJson) {
		return CloudDiskModule.moveCloudDiskNode(mstpClient, paramJson, null);
	}
	
	/**
	 * 移动网盘节点
	 * @param paramJson
	 * @param cacheJson
	 * @return
	 */
	public int moveCloudDiskNode(String paramJson, String cacheJson) {
		return CloudDiskModule.moveCloudDiskNode(mstpClient, paramJson, cacheJson);
	}
	
	/**
	 * 拷贝节点
	 * @param paramJson
	 * @return
	 */
	public int copyCloudDiskNode(String paramJson) {
		return CloudDiskModule.copyCloudDiskNode(mstpClient, paramJson, null);
	}
	
	/**
	 * 拷贝节点
	 * @param paramJson
	 * @param cacheJson
	 * @return
	 */
	public int copyCloudDiskNode(String paramJson, String cacheJson) {
		return CloudDiskModule.copyCloudDiskNode(mstpClient, paramJson, cacheJson);
	}
	
	/**
	 * 删除节点
	 * @param paramJson
	 * @return
	 */
	public int deleteCloudDiskNode(String paramJson) {
		return CloudDiskModule.deleteCloudDiskNode(mstpClient, paramJson);
	}
	
	/**
	 * 重命名
	 * @param paramJson
	 * @return
	 */
	public int renameCloudDiskNode(String paramJson) {
		return CloudDiskModule.renameCloudDiskNode(mstpClient, paramJson);
	}
	
	/**
	 * 分享节点
	 * @param paramJson
	 * @param cacheJson
	 * @return
	 */
	public int shareCloudDiskNode(String paramJson, String cacheJson) {
		return CloudDiskModule.shareCloudDiskNode(mstpClient, paramJson, cacheJson);
	}
	
	/**
	 * 分享节点
	 * @param paramJson
	 * @param cacheJson
	 * @return
	 */
	public int shareCloudDiskNode(String paramJson) {
		return CloudDiskModule.shareCloudDiskNode(mstpClient, paramJson, null);
	}
	
	/**
	 * 查询分享的节点信息
	 * @param paramJson
	 * @return
	 */
	public int querySharedNodesInfo(String paramJson) {
		return CloudDiskModule.querySharedNodesInfo(mstpClient, paramJson);
	}
	
	/**
	 * 取消分享
	 * @param paramJson
	 * @return
	 */
	public int unshareCloudDiskNode(String paramJson) {
		return CloudDiskModule.unshareCloudDiskNode(mstpClient, paramJson);
	}
	
	/**
	 * 转存
	 * @param paramJson
	 * @return
	 */
	public int dumpCloudDiskNode(String paramJson) {
		return CloudDiskModule.dumpCloudDiskNode(mstpClient, paramJson, null);
	}
	
	/**
	 * 转存
	 * @param paramJson
	 * @param cacheJson
	 * @return
	 */
	public int dumpCloudDiskNode(String paramJson, String cacheJson) {
		return CloudDiskModule.dumpCloudDiskNode(mstpClient, paramJson, cacheJson);
	}
	
	/**
	 * 批量取消分享
	 * @param paramJson
	 * @return
	 */
	public int batchUnshareCloudDiskNode(String paramJson) {
		return CloudDiskModule.batchUnshareCloudDiskNode(mstpClient, paramJson);
	}
	
	/**
	 * 创建话题
	 * @param paramJson
	 * @param cacheJson
	 * @return
	 */
	public int createTopic(String paramJson, String cacheJson) {
		return TopicModule.createTopic(mstpClient, paramJson, cacheJson);
	}
	
	/**
	 * 创建话题
	 * @param paramJson
	 * @return
	 */
	public int createTopic(String paramJson) {
		return TopicModule.createTopic(mstpClient, paramJson, null);
	}
	
	/**
	 * 更新话题
	 * @param paramJson
	 * @return
	 */
	public int updateTopic(String paramJson) {
		return TopicModule.updateTopic(mstpClient, paramJson);
	}
	
	/**
	 * 关闭话题
	 * @param paramJson
	 * @return
	 */
	public int closeTopic(String paramJson) {
		return TopicModule.function4Topic(mstpClient, paramJson, 0);
	}
	
	/**
	 * 打开话题
	 * @param paramJson
	 * @return
	 */
	public int openTopic(String paramJson) {
		return TopicModule.function4Topic(mstpClient, paramJson, 1);
	}
	
	/**
	 * 删除话题
	 * @param paramJson
	 * @return
	 */
	public int deleteTopic(String paramJson) {
		return TopicModule.function4Topic(mstpClient, paramJson, 3);
	}
	
	/**
	 * 置顶话题
	 * @param paramJson
	 * @return
	 */
	public int setTopTopic (String paramJson) {
		return TopicModule.function4Topic(mstpClient, paramJson, 4);
	}
	
	/**
	 * 放弃话题
	 * @param paramJson
	 * @return
	 */
	public int quitTopic(String paramJson) {
		return TopicModule.function4Topic(mstpClient, paramJson, 2);
	}
	
	/**
	 * 转移话题
	 * @param paramJson
	 * @return
	 */
	public int transferTopic(String paramJson) {
		return TopicModule.function4Topic(mstpClient, paramJson, 5);
	}
	
	/**
	 * 邀请成员加入话题
	 * @param paramJson
	 * @return
	 */
	public int inviteMembers(String paramJson) {
		return TopicModule.memberUpdate(mstpClient, paramJson, 0);
	}
	
	/**
	 * 移除话题成员
	 * @param paramJson
	 * @return
	 */
	public int removeMembers(String paramJson) {
		return TopicModule.memberUpdate(mstpClient, paramJson, 1);
	}

	/**
	 * 创建投票
	 * @param paramJson
	 * @return
	 */
	public int createVote(String paramJson) {
		return createVote(paramJson, null);
	}
	
	/**
	 * 创建投票（包含缓存参数）
	 * @param paramJson
	 * @param cacheJson
	 * @return
	 */
	public int createVote(String paramJson, String cacheJson) {
		return VoteModule.createVote(mstpClient, paramJson, cacheJson);
	}
	
	/**
	 * 发送评论并验证
	 * @param paramJson
	 * @param cacheJson
	 * @return
	 */
	public int sendMessageAndVerify(String paramJson, String cacheJson) {
		return syncSendMessage(paramJson, cacheJson);
	}
	
	/**
	 * 发送评论并验证
	 * @param paramJson
	 * @return
	 */
	public int sendMessageAndVerify(String paramJson) {
		return syncSendMessage(paramJson, null);
	}
	
	/**
	 * 验证评论或者回复
	 * @param paramJson
	 * @return
	 */
	public int commentAndReplyVerfiry(String paramJson) {
		return TopicModule.commentAndReplyVerfiry(mstpClient, paramJson);
	}
	
	/**
	 * 查询话题信息
	 * @param paramJson
	 * @param cacheJson
	 * @return
	 */
	public int queryTopicWithTopicId(String paramJson, String cacheJson) {
		return TopicModule.queryTopicWithTopicId(mstpClient, paramJson, cacheJson);
	}
	
	/**
	 * 取消置顶
	 * @param paramJson
	 * @return
	 */
	public int unsetTopTopic(String paramJson) {
		return TopicModule.function4Topic(mstpClient, paramJson, 6);
	}
	
	/**
	 * 查询话题信息
	 * @param paramJson
	 * @return
	 */
	public int queryTopicInfo(String paramJson) {
		return TopicModule.function4Topic(mstpClient, paramJson, 7);
	}
	
	/**
	 * 查询话题成员
	 * @param paramJson
	 * @return
	 */
	public int queryTopicMembers(String paramJson) {
		return TopicModule.function4Topic(mstpClient, paramJson, 8);
	}
	
	/**
	 * 查询所有节点
	 * @param paramJson
	 * @return
	 */
	public int queryAllNodes(String paramJson) {
		return TopicModule.function4Topic(mstpClient, paramJson, 9);
	}
	
	/**
	 * 提交投票
	 * @param paramJson
	 * @return
	 */
	public int submitVote(String paramJson) {
		return VoteModule.submitVote(mstpClient, paramJson);
	}
	
	/**
	 * 查询投票结果
	 * @param paramJson
	 * @return
	 */
	public int queryVoteResult(String paramJson) {
		return VoteModule.queryVoteResult(mstpClient, paramJson);
	}
	
	public int setAddedPolicy(String paramJson) {
		return BuddyModule.setAddedPolicy(mstpClient, paramJson);
	}
	public int getAddedPolicy(String paramJson) {
		return BuddyModule.getAddedPolicy(mstpClient, paramJson);
	}
	public int clearAllBuddy() {
		return BuddyModule.clearAllBuddy(mstpClient);
	}
	public int addBuddy(String paramJson) {
		return BuddyModule.addBuddy(mstpClient, paramJson);
	}
	public int refuseAddBuddy(String paramJson) {
		return BuddyModule.refuseAddBuddy(mstpClient, paramJson);
	}
	public int agreeAddBuddy(String paramJson) {
		return BuddyModule.agreeAddBuddy(mstpClient, paramJson);
	}
	public int setNickName(String paramJson) {
		return BuddyModule.setNickName(mstpClient, paramJson);
	}
	public int setExtraInfo(String paramJson) {
		return BuddyModule.setExtraInfo(mstpClient, paramJson);
	}
	public int removeBuddy(String paramJson) {
		return BuddyModule.removeBuddy(mstpClient, paramJson);
	}
	public int verifyContainBuddy(String paramJson) {
		return BuddyModule.verifyContainBuddy(mstpClient, paramJson);
	}
	public int reciveAddBuddyNotifyAndVerify(String paramJson) {
		return BuddyModule.reciveAddBuddyNotifyAndVerify(mstpClient, paramJson);
	}
	public int reciveAgreeAddBuddyNotifyAndVerify(String paramJson) {
		return BuddyModule.reciveAgreeAddBuddyNotifyAndVerify(mstpClient, paramJson);
	}
	public int reciveRefuseAddBuddyNotifyAndVerify(String paramJson) {
		return BuddyModule.reciveRefuseAddBuddyNotifyAndVerify(mstpClient, paramJson);
	}
}
